import matplotlib.pyplot as plt
import numpy as np

# 数据（100轮训练）
epochs = np.arange(1, 101)
delta_H = np.clip(0.5 * np.exp(-0.03 * epochs) + 0.05 * np.random.randn(100), 0, 1)
T = 0.8 * np.exp(-0.05 * np.cumsum(delta_H))  # 式(8)

# 绘制双Y轴曲线
fig, ax1 = plt.subplots(figsize=(10, 6))
ax1.plot(epochs, delta_H, 'b-', linewidth=2, label=r'$\Delta H^{(t)}$')
ax1.set_xlabel('Training Rounds', fontsize=12)
ax1.set_ylabel(r'Entropy Change Rate $\Delta H^{(t)}$', color='b', fontsize=12)
ax1.tick_params(axis='y', labelcolor='b')

ax2 = ax1.twinx()
ax2.plot(epochs, T, 'r--', linewidth=2, label=r'$T^{(t)}$')
ax2.set_ylabel(r'Temperature $T^{(t)}$', color='r', fontsize=12)
ax2.tick_params(axis='y', labelcolor='r')

# 标注演化阶段
ax1.axvline(x=30, color='gray', linestyle=':', alpha=0.7)
ax1.axvline(x=70, color='gray', linestyle=':', alpha=0.7)
ax1.text(10, 0.8, "Exploration Phase\n(High $T^{(t)}$)", fontsize=10, ha='center')
ax1.text(50, 0.8, "Transition Phase", fontsize=10, ha='center')
ax1.text(85, 0.8, "Convergence Phase\n(Low $T^{(t)}$)", fontsize=10, ha='center')

plt.title('Entropy-Temperature Co-evolution', fontsize=14)
fig.legend(loc='upper right', bbox_to_anchor=(0.9, 0.85))
plt.savefig('entropy_temperature_coevolution.png', bbox_inches='tight')
